package com.fy.paper.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fy.paper.entity.Paper;
import com.fy.paper.entity.PaperQuAnswer;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 试卷 Mapper 接口
 * </p>
 *
 * @author 
 * @since 2023-06-16
 */
public interface PaperMapper extends BaseMapper<Paper> {

    @Select("SELECT * FROM el_paper_qu_answer p\n" +
            "WHERE  p.paper_id = #{paperId}\n" +
            "AND p.qu_id = #{quId}\n" +
            "AND p.checked != p.is_right")
    public List<PaperQuAnswer> fillAnswerIsRight(@Param("paperId") String paperId,
                                                 @Param("quId") String quId);

    /**
     * 交卷时统计客观题得分
     */
    @Select("SELECT SUM(el_paper_qu.actual_score) AS obj_score FROM el_paper_qu\n" +
            "WHERE el_paper_qu.paper_id = #{paperId}\n" +
            "AND el_paper_qu.qu_type != 4\n" +
            "AND el_paper_qu.is_right = 1")
    public Map totalObjScoreWhenHandlePaper(String paperId);

}
